package com.cal.calendar;

import java.text.SimpleDateFormat;
import java.util.Date;


public final class DateUtil {
	
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");

	/**
	 * 返回指定月份的天数
	 * 
	 * @param year
	 * @param month
	 * @return
	 */
	public static int getDaysOfMonth(int year, int month) {

		if (year < 0 || month < 0 || month > 12) {
			return 0;
		}

		if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
				|| month == 10 || month == 12) {
			return 31;
		} else if (month == 4 || month == 6 || month == 9 || month == 11) {
			return 30;
		} else if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
			return 29;
		} else {
			return 28;
		}
	}
	
	/**
	 * 格式化日期为yyyy年MM月
	 * @param date
	 * @return
	 */
	public static String formatDate(Date date){
		return sdf.format(date);
	}
	
	/**
	 * 比较两个日期是否为同一天
	 * @param first
	 * @param last
	 * @return true:是 / false:不是
	 */
	public static boolean equalsTwoDate(Date first ,Date last){
		
		return (first.getYear() == last.getYear())
				&& (first.getMonth() == last.getMonth())
				&& (first.getDate() == last.getDate());
	}
}
